package top.jacktgq.sxt.bio.demo1;

import java.net.MalformedURLException;
import java.net.URL;

/**
 * @Author CandyWall
 * @Date 2019/10/20--17:08
 * @Description URL：统一资源定位器，互联网三大基石之一（html http），区分资源
 *                  http://www.baidu.com:80/index.html?username=zhangsan&age=18#a
 *                  1、协议(http)
 *                  2、域名、计算机(www.baidu.com)
 *                  3、端口：默认80(80)
 *                  4、请求资源(index.html)
 */
public class URLTest {
    public static void main(String[] args) throws MalformedURLException {
        URL url = new URL("https://image.baidu.com/search/detail?ct=503316480&z=0&ipn=d&word=http%20%E5%92%8C%20tcp%E5%8D%8F%E8%AE%AE%E7%9A%84%E5%8C%BA%E5%88%AB&step_word=&hs=0&pn=4&spn=0&di=6490&pi=0&rn=1&tn=baiduimagedetail&is=0%2C0&istype=0&ie=utf-8&oe=utf-8&in=&cl=2&lm=-1&st=undefined&cs=3610877997%2C1195361632&os=2075581486%2C857254473&simid=3339999752%2C268041437&adpicid=0&lpn=0&ln=545&fr=&fmq=1571565638763_R&fm=&ic=undefined&s=undefined&hd=undefined&latest=undefined&copyright=undefined&se=&sme=&tab=0&width=undefined&height=undefined&face=undefined&ist=&jit=&cg=&bdtype=0&oriquery=&objurl=http%3A%2F%2Fuphotos.eepw.com.cn%2Ffetch%2F20180719%2F385019_1_0.jpg&fromurl=ippr_z2C%24qAzdH3FAzdH3Fooo_z%26e3Bjjro_z%26e3Bv54_z%26e3BvgAzdH3Fw6ptvsjAzdH3Fda8babAzdH3Fnbca8l_z%26e3Bip4&gsm=&rpstart=0&rpnum=0&islist=&querylist=&force=undefined");
        //获取四个值：协议、域名、计算机、端口：默认80(80)、请求资源(index.html)
        System.out.println("协议：" + url.getProtocol());
        System.out.println("域名：" + url.getHost());
        System.out.println("端口：" + url.getPort());
        System.out.println("请求资源1：" + url.getPath());
        System.out.println("请求资源2：" + url.getFile());

        //参数
        System.out.println("参数" + url.getQuery());
        //锚点
        System.out.println("锚点" + url.getRef());
    }
}
